/**
 * 
 */
package gpl.scotlandyard.android.utils;

import android.util.Log;

/**
 * @author norbert
 */
public final class InputValidator {

  private static final String TAG = InputValidator.class.toString();

  private InputValidator() {
  }

  /** Validates the input format and limits and returns value.
   * @param position to get
   * @param min included
   * @param max included
   * @return position or -1 if not valid.
   */
  public static int isValidPosition(String position, int min, int max) {
    if ("".equals(position.trim())) {
      return -1;
    }
    try {
      int setPosition = Integer.parseInt(position.trim());
      if (setPosition < min || setPosition > max) {
        return -1;
      }
      return setPosition;
    } catch (NumberFormatException e) {
      Log.d(TAG, e.getLocalizedMessage());
      return -1;
    }
  }
}
